Skip to content

Add --site-path filter to wp site list to avoid conflict with global --path#595

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-wp-site-list-path-filter
Open

Add --site-path filter to wp site list to avoid conflict with global --path#595
Copilot wants to merge 4 commits intomainfrom
copilot/fix-wp-site-list-path-filter

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

wp site list documents path as a filterable field, but --path is a global WP-CLI parameter (WordPress install directory), so it's silently consumed before reaching the command in normal usage — making path-based filtering impossible without strict args mode.

Changes

  • src/Site_Command.php: Keeps path in the generic $site_cols auto-mapping loop (so --path continues to work as a field filter when WP_CLI_STRICT_ARGS_MODE=1 is set), and adds explicit handling for --site-path=<path>, which maps to the path column in wp_blogs.
  • Docblock: Documents --site-path and notes that --path conflicts with the global parameter in normal usage, recommending --site-path instead.
  • features/site.feature: Adds a Behat scenario asserting --site-path correctly filters results.

Usage

# Works in strict args mode (WP_CLI_STRICT_ARGS_MODE=1)
wp site list --path=/first/

# Works in all modes (recommended)
wp site list --site-path=/first/
Original prompt

This section details on the original issue you should resolve

<issue_title>Unable to use wp site list to filter sites by path</issue_title>
<issue_description>## Bug Report

The wp site list command supports filtering to specific fields, such as domain:
wp site list --domain=wordpress.org
and the documentation suggests it can filter to the path, but the parameter conflicts with the global --path parameter.

The code seems to suggest it's possible too:
https://github.com/wp-cli/entity-command/blob/master/src/Site_Command.php#L558-L563

It should be possible to list sites by their path component somehow, eg: wp site list --field-path=/support/

Let us know what environment you are running this on

OS:	Linux 4.9.0-5-amd64 wp-cli/entity-command#1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04) x86_64
PHP version:	7.2.28
WP-CLI version:	2.4.0

</issue_description>

Comments on the Issue (you are @copilot in this section)

@dd32 Thanks @ocean90! I still feel this is a bug and there should at least be a prefixed variant of the args if strict mode is never going to be enforced.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix filtering by path in wp site list command Add --site-path filter to wp site list to avoid conflict with global --path Mar 15, 2026
Copilot AI requested a review from swissspidy March 15, 2026 13:24
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI requested a review from swissspidy March 15, 2026 15:51
@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy marked this pull request as ready for review March 15, 2026 21:54
@swissspidy swissspidy requested a review from a team as a code owner March 15, 2026 21:54
Copilot AI review requested due to automatic review settings March 15, 2026 21:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR resolves a long-standing usability issue in wp site list where filtering by the path field is effectively blocked by WP-CLI’s global --path parameter in non-strict args mode, by introducing a non-conflicting --site-path option.

Changes:

  • Document the --path global-arg conflict and add a new --site-path=<path> option to enable reliable path-based filtering.
  • Implement --site-path handling by mapping it to the path column filter.
  • Add a Behat scenario validating --site-path filtering behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Site_Command.php Adds --site-path option documentation and maps it to the path filter in wp site list.
features/site.feature Adds an acceptance test scenario to ensure --site-path filters the site list correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +1053 to +1055
if ( isset( $assoc_args['site-path'] ) ) {
$where['path'] = $assoc_args['site-path'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:network Related to 'network' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to use wp site list to filter sites by path

3 participants